#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<cmath>
using namespace std;
bool ws(int x)
{
	if (x >= 10 && x < 100 && x != 11) return 0;
	if (x >= 1000 && x < 10000) return 0;
	if (x >= 100000 && x < 1000000) return 0;
	if (x >= 10000000&&x<100000000) return 0;
	return 1;
}
bool hw(int x)
{
	int a[10];
	int n = 0;
	while (x)
	{
		a[n] = x % 10;
		x = x / 10;
		n++;
	}
	for (int i = 0; i < n; i++)
	{
		if (a[i] != a[n - i - 1]) return 0;
	}
	return 1;
}
bool ss(int x)
{
	if (x <= 1) return 0;
	for (int i = 2; i <= sqrt(x); i++)
	{
		if (x % i == 0) return 0;
	}
	return 1;
}
int main()
{
	int a, b;
	scanf("%d%d", &a, &b);
	if (a % 2 == 0) a += 1;
	for (int i = a; i <= b; i+=2)
	{
		if (ws(i) && hw(i) && ss(i))
			printf("%d\n", i);
	}
	return 0;
}